package com.example.demo.controller;

import com.example.demo.poji.DtoThree;
import com.example.demo.poji.Dtoaaa;
import com.example.demo.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RequestMapping("/demo")
@RestController
public class DemoController {

    @Autowired
    private DemoService demoService;

    @RequestMapping("/dict/list")
    public Map loadDictList() {
        Map result = new HashMap();
        try {
            Map param = new HashMap();
            List<Map> dictList = demoService.loadDictList(param);
            result.put("success", true);
            result.put("datalist", dictList);
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "查询错误");
            e.printStackTrace();
        }
        return result;
    }

    //    第一题
    @RequestMapping("/allone")
    public List<Map> allone() {
        List<Map> allons = demoService.allons();
        return allons;
    }

    //    第二题
    @RequestMapping("/alltwo")
    public List<Map> alltwo() {
        List<Map> alltwo = demoService.alltwo();
        return alltwo;
    }

    //    第三题
    @RequestMapping("/allthere")
    public List<Map<String, List<Dtoaaa>>> allthere() {
        List<Map<String, List<Dtoaaa>>> alltwo = demoService.allthree();
        return alltwo;
    }

    //    第四题
    @RequestMapping("/allfive")
    public List<DtoThree> allfive() {
        List<DtoThree> alltwo = demoService.allfour();
        return alltwo;
    }

    //测试数据
    @RequestMapping("/mock")
    public Map demoMock() {
        Map result = new HashMap();
        try {

            Random random = new Random();
            for (int i = 1; i < 5000; i++) {
                String tjrq = "";
                int k = i % 10;
                if (k == 0) {
                    k = 1;
                }
                if (k < 10) {
                    tjrq = "2022-12-0" + k;
                } else {
                    tjrq = "2022-12-" + k;
                }

                Map pm = new HashMap();
                pm.put("tjrq", tjrq);
                pm.put("tjlb", "LB00" + i % 3);
                pm.put("tjnum", random.nextInt(1000));
                demoService.savadata(pm);
            }
            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "查询错误");
            e.printStackTrace();
        }
        return result;
    }
}
